package com.example.webchar.webchar.mapper.master;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.webchar.webchar.pojo.ChapterName;
import com.example.webchar.webchar.pojo.NovelContent;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @program: wechat-web-is-my
 * @description
 * @author: 郭逍
 * @create: 2021/8/21 10:57
 **/
@Mapper
@Service
public interface NovelContentMaster extends BaseMapper<NovelContent> {
    /**
     * 往content表中批量插入信息
     *
     * @param list
     */
    @Insert("<script>insert into novel_content(chapter_name_id,content,next_page,up_page) values" +
            "<foreach collection=\"list\" item=\"item\" index=\"index\"  separator=\",\"> " +
            "(#{item.chapterNameId},#{item.content},#{item.nextPage},#{item.upPage})" +
            "</foreach></script>")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void insNovelContentList(@Param("list") List<NovelContent> list);

    /**
     * 批量删除内容中的小说信息
     *
     * @param chapterNames
     */
    @Delete("<script> delete from novel_content where chapter_name_id in <foreach  item='item' index='index' collection='chapterNames' open='(' separator=',' close=')'> #{item.id}</foreach></script> ")
    void deleteNovelContentByChapterNameId(@Param("chapterNames") List<ChapterName> chapterNames);
}
